package ita.class1.group2.supermarket.administrator.service;

import ita.class1.group2.supermarket.administrator.dao.UserDaoImpl;
import ita.class1.group2.supermarket.administrator.pojo.User;
import ita.class1.group2.supermarket.common.annotation.Autowired;
import ita.class1.group2.supermarket.common.annotation.Component;
import ita.class1.group2.supermarket.common.dao.BaseDao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class AdminService {

    @Autowired
    private UserDaoImpl userDao;

    public User login(User admin) {
        Map<String,String> map = new HashMap<String,String>();
        map.put("username",admin.getUsername());
        List users = userDao.findByCondition(map);
        if(users != null && users.size() == 1){
            User user = (User) users.get(0);
            if(user.getPassword().equals(admin.getPassword())){
               return user;
            }
        }
        return null;
    }

    public User getUser(String id) {
        if(id == null) return null;
        return (User) userDao.find(id);
    }
}
